package leetcode.editor.cn1.study01;

public class ShuZuZhongZhongFuDeShuZiLcof {
    public static void main(String[] args) {
        Solution solution = new ShuZuZhongZhongFuDeShuZiLcof().new Solution();
        System.out.println(solution.findRepeatNumber(new int[]{2, 3, 1, 0, 2, 5, 3}));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findRepeatNumber(int[] nums) {
            // 重复数字不存在
            if (nums.length < 2)
                return -1;
            // 三种解题思路
            // 1. hash
            // 2. set集合（不可重复）
            // 3. 定义一个数组
            int nlen = nums.length;
            int[] dp = new int[nlen];
            for (int i = 0; i < nlen; i++) {
                if (dp[nums[i]] == 1) {
                    return nums[i];
                } else {
                    dp[nums[i]] = 1;
                }
            }
            return -1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
